## Assumes that the current working dir is the top level of the archive

home <- getwd()
library(foreign)
source(paste(home,"/bits/scripts/runBigMahal_BITs.R",sep=""))

HRA <- "opt1"

## All observation matching
if(!file.exists(paste(home,"/bits/madedata/mahmatches_",HRA,"bit.dta",sep=""))){
  runBigMahal_BITs(HRA=HRA, 
    inData=paste(home,"/bits/madedata/",HRA,"RatEpisodeDat.dta",sep=""),
    outData=paste(home,"/bits/madedata/mahmatches_",HRA,"bit.dta",sep=""))
}

## OECDname2==0 & OECD==1  (so we are looking at decisions by OECD members to ratify with non-OECD countries)
if(!file.exists(paste(home,"/bits/madedata/mahmatches_",HRA,"bit_OECD.dta",sep=""))){
  runBigMahal_BITs(HRA=HRA, 
    inData=paste(home,"/bits/madedata/",HRA,"RatEpisodeDat_OECD.dta",sep=""),
    outData=paste(home,"/bits/madedata/mahmatches_",HRA,"bit_OECD.dta",sep=""))
}

## if HRAname_1==1 & HRAname_2==0 (looking at decisions by ratifiers to sign with other countries that have not yet ratified)
if(!file.exists(paste(home,"/bits/madedata/mahmatches_",HRA,"bit_Ratifiers.dta",sep=""))){
  runBigMahal_BITs(HRA=HRA, 
    inData=paste(home,"/bits/madedata/",HRA,"RatEpisodeDat_Ratifiers.dta",sep=""),
    outData=paste(home,"/bits/madedata/mahmatches_",HRA,"bit_Ratifiers.dta",sep=""))
}

## if HRAname_2==0 (looking at decisions by ratifiers to sign with other countries that have not yet ratified)
if(!file.exists(paste(home,"/bits/madedata/mahmatches_",HRA,"bit_nonRatifiers.dta",sep=""))){
  runBigMahal_BITs(HRA=HRA, 
    inData=paste(home,"/bits/madedata/",HRA,"RatEpisodeDat_nonRatifiers.dta",sep=""),
    outData=paste(home,"/bits/madedata/mahmatches_",HRA,"bit_nonRatifiers.dta",sep=""))
}
